/**
 * @Author:  renyc
 * @Date: 2022年12月21日17:39:05
 */

import * as Cesium from "cesium/Cesium";

import Util from "../../utils/Util";
import PrimitiveOverlay from "./PrimitiveOverlay";

class GroundPolylinePrimitive extends PrimitiveOverlay{

    constructor(coordinates, options){
        super();
        this._coordinates = coordinates;
        this._options = options;
        this._delegate = undefined;

        if(this._coordinates){
            this._delegate = this._createPrimivive();
        }
    }

    // _createPrimivive(){

    //     let instance = new Cesium.GeometryInstance({
    //         geometry : new Cesium.GroundPolylineGeometry({
    //            positions : Cesium.Cartesian3.fromDegreesArray([
    //                116, 39,
    //                116, 40,
    //                117, 40
    //            ]),
    //            width : 4.0
    //         }),
    //         id : 'object returned when this instance is picked and to get/set per-instance attributes'
    //       });
          
    //       let primitive = new Cesium.GroundPolylinePrimitive({
    //         geometryInstances : instance,
    //         appearance : new Cesium.PolylineMaterialAppearance()
    //       });

    //     return primitive;
    // }
    
    _createPrimivive(){
        // let coordiates = [
        //     116, 39,
        //     116, 40,
        //     117, 40
        // ];
        let coordiates = this._coordinates;
        let geometry = new Cesium.GroundPolylineGeometry({
            positions : Cesium.Cartesian3.fromDegreesArray(coordiates),
            width : 4.0
        });
        let instance = new Cesium.GeometryInstance({
            id : this._id,
            geometry : geometry
        });        
        
        // let appearance = new Cesium.PolylineMaterialAppearance({
        //     material : Cesium.Material.fromType('Color')
        // });
        let appearance = new Cesium.PolylineMaterialAppearance({
            flat: true,
            material: Cesium.Material.fromType(
                Cesium.Material.PolylineDashType, {
                    color: Cesium.Color.CYAN, //线条颜色
                    gapColor: Cesium.Color.TRANSPARENT, //间隔颜色
                    dashLength: 20, //短划线长度
                }
            ),
        });
            // let appearance = new Cesium.PolylineMaterialAppearance({
            //     flat: true,
            //     material: Cesium.Material.fromType(
            //         Cesium.Material.PolylineArrow, {
            //             color: Cesium.Color.CYAN
            //         }
            //     ),
            // });
            // let appearance = new Cesium.PolylineMaterialAppearance({
            //     material: Cesium.Material.fromType(Cesium.Material.PolylineArrow),
            // });
        let primitive = new Cesium.GroundPolylinePrimitive({
            geometryInstances : instance,
            appearance : appearance
        });

        return primitive;
    }

    // _createPrimivive(){
    //     // let coordinates = [
    //     //     116, 39,
    //     //     116, 40,
    //     //     117, 40,
    //     // ];
    //     let coordinates = this._coordinates;
    //     let polyline = new Cesium.GroundPolylineGeometry({
    //         id: this._id,    
    //         positions : Cesium.Cartesian3.fromDegreesArray(coordinates),
    //         with : 10.0,
    //         //vertexFormat : Cesium.PolylineColorAppearance.VERTEX_FORMAT
    //     });
    //     let solidWhite = Cesium.ColorGeometryInstanceAttribute.fromColor(Cesium.Color.WHITE);

    //     let geometryInstance = new Cesium.GeometryInstance({
    //         id : Util.uuid(),
    //         geometry : polyline,
    //         // attributes : {
    //         //     color : solidWhite
    //         // }
    //     });
    //     geometryInstance.delegate = this._delegate;

    //     //2. 创建Apperance实例
    //     // let appearance = new Cesium.PolylineColorAppearance({
    //     //     translucent : false
    //     // });
    //     // let appearance = new Cesium.PolylineMaterialAppearance({
    //     //     flat: true,
    //     //     material: Cesium.Material.fromType(Cesium.Material.PolylineDashType, {
    //     //       color: Cesium.Color.CYAN, //线条颜色
    //     //       gapColor: Cesium.Color.TRANSPARENT, //间隔颜色
    //     //       dashLength: 20, //短划线长度
    //     //     }),
    //     //   });

    //     let appearance = new Cesium.PolylineMaterialAppearance({
    //         material : Cesium.Material.fromType('Color')
    //     });

    //     let primitive = new Cesium.Primitive({
    //         // 利用新创建的instance为Primitive的geometryInstance属性赋值
    //         geometryInstances: geometryInstance,
    //         // 定义instance的apperance
    //         appearance: appearance,
    //     });

    //     return primitive;
    // }
}

export default GroundPolylinePrimitive
